TOKEN_TYPE = ("TOKEN_TYPE_NUMBER", "TOKEN_TYPE_OPERATOR")
LIST_OPERATOR = ("+", "-", "*", "/")

def Tokenize(expression):
    """
    将给定的数学表达式字符串进行分词处理。
    
    Args:
        expression (str): 需要分词的数学表达式字符串。
    
    Returns:
        list: 分词后的结果列表，每个元素是一个字典，包含单词（"word"）和类型（"type"）两个键。
            单词类型为"TOKEN_TYPE_NUMBER"表示数字，为"TOKEN_TYPE_OPERATOR"表示操作符。
    
    Raises:
        SystemExit: 如果遇到错误的数字格式，则打印错误信息并退出程序。
    
    """
    tokens = []
    i = 0
    while i < len(expression):
        if expression[i].isdigit() or expression[i] == '.':  # 检查是否是数字
            word = ""
            startPos = i
            while i < len(expression) and (expression[i].isdigit() or expression[i] == '.'):
                word += expression[i]
                i += 1
            try:
                intWord = float(word)
                tokens.append({"word": word, "type": "TOKEN_TYPE_NUMBER"})
            except:
                print("error: wrong number, at position %d-%d." % (startPos,i))
                exit
        elif expression[i] in LIST_OPERATOR:  # 检查是否是操作符
            tokens.append({"word": expression[i], "type": "TOKEN_TYPE_OPERATOR"})
            i += 1
        else:  # 忽略其他字符
            i += 1
    return tokens

if __name__ == "__main__":
    # 测试函数
    print("test 1")
    expression = "11+2 + 255.33.456.1"
    tokens = Tokenize(expression)
    for token in tokens:
        print(token)
